const realTimeStatus = {
    namespaced: true,
    state: {
        TableItem: [],
        pagination: [],
        curPage: 1,
        pageSize: 10,
        dataTotal:0,
    },
    getters: {
        getTableData: (state) => {
            return state.pagination;
        },
        getCurPage: (state) => {
            return state.curPage;
        },
        getpageSize: (state) => {
            return state.pageSize;
        },
        getDataTotal: (state) => {
            return state.dataTotal;
        },
    },
    mutations: {
        pagination: (state) => {
            state.pagination = []
            if (state.TableItem) {
                for (let i = (state.curPage - 1) * state.pageSize; i < (state.pageSize * state.curPage) && i < state.TableItem.length; i++) {
                    if (i > state.dataTotal - 1) {
                        break;
                    }
                    state.pagination.push(state.TableItem[i])
                }
            }
        },
    },
    actions: {
        getPaginationCurPage({commit, state},val){
            state.curPage = val;
            commit('pagination');
        },
        getPaginationPageSize({commit, state},val){
            state.curPage = 1;
            state.pageSize = val;
            commit('pagination');
        },
        setTableData({commit, state},val){
            state.TableItem = [];
            state.TableItem = [...val];
            state.dataTotal = [...val].length;
            state.curPage= 1;
            state.pageSize= 10;
            commit('pagination');
        },
    }
};

export default realTimeStatus;